<template>
  <el-dialog title="新增员工" :visible="showDialog" width="150">
    <!-- 表单 -->
    <el-form label-width="120px"
    :model="amend"
    :rules="rules"
    ref="staff">
      <el-form-item
      label="学科名称"
      >
        <el-input style="width:50%" placeholder="请输入学科名称" v-model="amend.subjectName"/>
      </el-form-item>
      <el-form-item label="是否显示">
      <el-switch
      v-model="amend.isFrontDisplay"
      active-color="#13ce66"
      inactive-color="#ff4949"
      :active-value="1"
      :inactive-value="0">
      </el-switch>
    </el-form-item>
    </el-form>
    <!-- footer插槽 -->
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-col :span="6">
          <el-button size="small" @click="cancel">取消</el-button>
          <el-button type="primary" size="small" @click="btnOk">确定</el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { addsubject } from '@/api/hmmm/jjqsubject'
export default {
  data () {
    return {
      data: {
        subjectName: '',
        value: '0'
      },
      rules: {
        subjectName: [
          // required设置是否必填 如果不设置会根据校验规则自动设置
          { required: true, message: '课程名称不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    amend: {
      type: Object
    }
  },
  methods: {
    async btnOk () {
      try {
        await this.$refs.userForm.validate()
        await addsubject(this.data)
        this.$message.success('添加成功')
        this.$emit('update:showDialog', false)
        this.$parent.getsubjectsList()
        this.$refs.staff.resetFields()
      } catch (error) {
        this.$message.error('添加失败')
      }
    },
    cancel () {
      this.$emit('update:showDialog', false)
      this.$refs.staff.resetFields()
    }
  }
}
</script>

<style>

</style>
